package com.plian.system.controller.pm.propertychange;

import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.dto.pm.property.PropertyChangeDTO;
import com.plian.system.model.ListResult;
import com.plian.system.model.ObjResult;
import com.plian.system.model.R;
import com.plian.system.service.pm.propertychange.PropertyChangeService;
import com.plian.system.vo.report.ReportReturnVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping(value = "api/propertyChange")
public class PropertyChangeController extends BaseController {
    @Autowired
    PropertyChangeService propertyChangeService;
    @PostMapping(value = "/save")
    public ObjResult save(@RequestBody PageData pd) throws Exception {
        //参数userName，passWord
        return propertyChangeService.save(pd);
    }
    @PostMapping(value = "/edit")
    public ObjResult edit(@RequestBody PageData pd) throws Exception {
        return propertyChangeService.edit(pd);
    }

    /**
     * 根据id查询
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/findid")
    public ObjResult findid(@RequestBody PageData pd) throws Exception {
        return propertyChangeService.findbyid(pd);
    }
    /**
     * 根据id查询数据及从表数据
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/findidAll")
    public ObjResult findbyidAll(@RequestBody PageData pd) throws Exception {
        return propertyChangeService.findbyidAll(pd);
    }

    /**
     * 根据集合删除数据
     * @param pd
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/del_ids")
    public ObjResult delids(@RequestBody PageData pd) throws Exception {
        return propertyChangeService.del_ids((List<String>) pd.get("ids"));
    }
    /**
     * 查询列表
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/list")
    public ListResult listpage(@RequestBody PageData pd) throws Exception {
        return propertyChangeService.listPage(pd);
    }
    @PostMapping(value = "/reportList")
    public ListResult reportList(@RequestBody PageData pd){
        return propertyChangeService.reportList(pd, false);
    }
    @PostMapping(value = "/reportListPage")
    public ListResult reportListPage(@RequestBody PageData pd){
        return propertyChangeService.reportList(pd, true);
    }

    @PostMapping(value = "/changeReasonCount")
    public R<ReportReturnVO> changeReasonCount(@RequestBody PropertyChangeDTO propertyChangeDTO){
        return propertyChangeService.changeReasonCount(propertyChangeDTO);
    }
    @PostMapping(value = "/exportChangeReasonCount")
    public void exportChangeReasonCount(@RequestBody PropertyChangeDTO propertyChangeDTO, HttpServletRequest request, HttpServletResponse response){
        propertyChangeService.exportExcelofEconomicBehavior(propertyChangeDTO,request,response);
    }
    @PostMapping(value = "/exportChangeReasonOrgDetail")
    public void exportChangeReasonOrgDetail(@RequestBody PropertyChangeDTO propertyChangeDTO, HttpServletRequest request, HttpServletResponse response){
        propertyChangeService.exportExcelofEconomicBehaviorDetail(propertyChangeDTO,request,response);
    }
}
